using System;

namespace Dida
{
	public struct Colour
	{
		public float r;
		public float g;
		public float b;
		public float a;

		public Colour(float r, float g, float b)
		{
			this.r = r;
			this.g = g;
			this.b = b;
			a = 1;
		}

		public Colour(float r, float g, float b, float a)
		{
			this.r = r;
			this.g = g;
			this.b = b;
			this.a = a;
		}

		public UInt32 ToUInt32()
		{
			int rByte = (int)(r * 255);
			if (rByte < 0)
				rByte = 0;
			else if (rByte > 255)
				rByte = 255;

			int gByte = (int)(g * 255);
			if (gByte < 0)
				gByte = 0;
			else if (gByte > 255)
				gByte = 255;

			int bByte = (int)(b * 255);
			if (bByte < 0)
				bByte = 0;
			else if (bByte > 255)
				bByte = 255;

			int aByte = (int)(a * 255);
			if (aByte < 0)
				aByte = 0;
			else if (aByte > 255)
				aByte = 255;

			return CreateUInt32Colour(rByte, gByte, rByte, aByte);
		}

		public static UInt32 CreateUInt32Colour(byte r,byte g,byte b,byte a)
		{
			return ((uint)a << 24) + ((uint)r << 16) + ((uint)g << 8) + b;
		}

		public static UInt32 CreateUInt32Colour(byte r, byte g, byte b)
		{
			return (uint)0xff000000 + ((uint)r << 16) + ((uint)g << 8) + b;
		}

		public static UInt32 CreateUInt32Colour(int r, int g, int b, int a)
		{
			return CreateUInt32Colour((byte)r, (byte)g, (byte)b, (byte)a);
		}

		public static UInt32 CreateUInt32Colour(int r, int g, int b)
		{
			return CreateUInt32Colour((byte)r, (byte)g, (byte)b);
		}
	}
}